﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace LinqExtender.Ast
{
    public class MemberExpression : Expression
    {
        private BucketItem item;

        internal MemberExpression(BucketItem item)
        {
            this.item = item;
        }

        /// <summary>
        /// Gets the name of the member.
        /// </summary>
        public string Name
        {
            get
            {
                return this.item.Name;
            }
        }

        /// <summary>
        /// Gets the full name of the member.
        /// </summary>
        public string FullName
        {
            get
            {
                return this.item.FullName;
            }
        }

        /// <summary>
        /// Gets the declaring type for the member.
        /// </summary>
        public Type DeclaringType
        {
            get
            {
                return this.item.DeclaringObjectType;
            }
        }

        /// <summary>
        /// Finds the target custom attribute for the member.
        /// </summary>
        public T FindAttribute<T>()
        {
            return (T)item.FindAttribute(typeof(T));
        }

        public override CodeType CodeType
        {
            get { return CodeType.MemberExpression; }
        }
    }
}
